package com.navinfo.platform.hbase.sample;

import com.navinfo.platform.hbase.api.RowMapper;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PeopleRowMapper implements RowMapper<PeopleDto> {
    private static final Logger LOGGER = LoggerFactory.getLogger(PeopleRowMapper.class);

    private static byte[] COLUMNFAMILY = "people".getBytes();
    private static byte[] NAME = "name".getBytes();
    private static byte[] AGE = "age".getBytes();

    public PeopleDto mapRow(Result result, int rowNum) throws Exception {
        PeopleDto dto = new PeopleDto();
        //LOGGER.info("---dto----1111------start-----------");
        //LOGGER.info(dto.toString());
        //LOGGER.info("---dto-----1111-----end-----------");
        // TODO: 设置相关的属性值
        String name = Bytes.toString(result.getValue(COLUMNFAMILY, NAME));
        dto.setName(name);
        Integer age=-1;
        if (null != result.getValue(COLUMNFAMILY, AGE))
        {
            age = new Integer(Bytes.toString(result.getValue(COLUMNFAMILY, AGE)));
            dto.setAge(age);
        }
        return dto;
    }
}
